//
// RawSocket.cpp
//
// $Id: //poco/1.4/Net/src/RawSocket.cpp#1 $
//
// Library: Net
// Package: Sockets
// Module:  RawSocket
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/Net/RawSocket.h"
#include "Poco/Exception.h"


using Poco::InvalidArgumentException;


namespace Poco {
namespace Net {


RawSocket::RawSocket(IPAddress::Family family,int proto): 
	Socket(SOCK_RAW)
{
	initSocket(family,SOCK_RAW,proto);
	setOption(IPPROTO_IP, IP_HDRINCL, 0);
}


RawSocket::RawSocket(const SocketAddress& address, bool reuseAddress,int proto): 
	Socket(SOCK_RAW)
{
	initSocket(address.family(),SOCK_RAW,proto);
	setOption(IPPROTO_IP, IP_HDRINCL, 0);
	Socket::bind(address, reuseAddress);
}


RawSocket::RawSocket(const Socket& socket,int proto): Socket(socket)
{
	if (getSocketType() != SOCK_RAW)
		throw InvalidArgumentException("Cannot assign incompatible socket");
	initSocket(socket.address().family(),SOCK_RAW,proto);
	setOption(IPPROTO_IP, IP_HDRINCL, 0);
}


RawSocket::~RawSocket()
{
}


RawSocket& RawSocket::operator = (const Socket& socket)
{
	if (getSocketType() != SOCK_RAW)
		throw InvalidArgumentException("Cannot assign incompatible socket");
	Socket::operator = (socket);
	return *this;
}


void RawSocket::connect(const SocketAddress& address)
{
	Socket::connect(address);
}


void RawSocket::bind(const SocketAddress& address, bool reuseAddress)
{
	Socket::bind(address, reuseAddress);
}


int RawSocket::sendBytes(const char* buffer, int length, int flags)
{
	return Socket::sendBytes(buffer, length, flags);
}


int RawSocket::receiveBytes(char* buffer, int length, int flags)
{
	return Socket::recvBytes(buffer, length, flags);
}


int RawSocket::sendTo(const char* buffer, int length, const SocketAddress& address, int flags)
{
	return Socket::sendTo(buffer, length, address, flags);
}


int RawSocket::receiveFrom(char* buffer, int length, SocketAddress& address, int flags)
{
	return Socket::recvFrom(buffer, length, address, flags);
}


} } // namespace Poco::Net
